﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetfractionHub.Network.Protocol.BASE.Factory
{
    public class FactoryRES : ProtocolMessageFactory
    {
        public enum ParameterEnum : int
        {
            SessionId = 1,
            VirtualFilePath = 2,
            FileSize = 3,
            SlotsAvailable = 4,
            Token = 5
        }

        public override ProtocolMessage Create(ProtocolMessage.MessageTypeEnum messageType, Dictionary<int, object> parameters)
        {
            ProtocolMessage proto = new ProtocolMessage(messageType, ProtocolFeatureBASE.FeatureActions.ActionRES);

            foreach (ParameterEnum en in parameters.Keys)
            {
                proto.Parameters.Add(new ProtocolParameter(GetParameterCodeForParameter((ParameterEnum)en), parameters[(int)en].ToString()));
            }
            
            return proto;
        }

        private string GetParameterCodeForParameter(ParameterEnum param)
        {
            switch (param)
            {
                case ParameterEnum.SessionId:
                    return "";
                case ParameterEnum.VirtualFilePath:
                    return "FN";
                case ParameterEnum.FileSize:
                    return "SI";
                case ParameterEnum.SlotsAvailable:
                    return "SL";
                case ParameterEnum.Token:
                    return "TO";
                default:
                    return "";
            }
        }
    }
}
